const sql = require('mssql')

sql.on('error', err => {
    console.log("sql server遇到了问题：%o", err)
})
const config = {
    user: 'sa',
    password: 'GJPF4.7PTW4',
    server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
    database: 'partlib',
    // pool: {
    //     max: 10,
    //     min: 1,
    //     idleTimeoutMillis: 30000
    // },
    options:{
        useColumnNames: true,
        appName: 'vic111',
        driver: 'msnodesqlv8' //tedious, msnodesqlv8 or msnodesql or tds    
    }
}
async function fun1() { 

    try {

        console.log(333)
        let pool = await sql.connect(config)
        return await pool.request()
            .input('CreateBy', sql.VarChar, "shi%" )
            .query('select top 1 * from p_Manufacturer where CreateBy LIKE @CreateBy')
            
        //console.dir(result1)

        // Stored procedure
        
        // let result2 = await pool.request()
        //     .input('input_parameter', sql.Int, value)
        //     .output('output_parameter', sql.VarChar(50))
        //     .execute('procedure_name')
        
        // console.dir(result2)
    } catch (err) {
        console.log("查询出错了： ", err)
    }  
    console.log(" 继续向前跑 " )  
}; 
async function fun2() { 
    var recordsets = await fun1();
    console.log(typeof recordsets[0] );
    if( recordsets[0].length > 0) {
        return (manufacture.recordsets[0][0]);
    }
};
fun2();